Repository navigation
feat(search): add hybrid FTS + pgvector job matching with OpenRouter embeddings - #112
Merged
Merged
Conversation
…embeddings - Flyway V37: pgvector extension and semantic_embeddings (vector(1024), FKs with cascade, content hash, model/dimensions, status, attempts, timestamps) - OpenRouter /embeddings client with batching, Matryoshka truncation, timeouts, token/cost/latency metrics - Polling sync: backfill, hash-based change detection, model switches, retries with backoff and SKIP LOCKED leases; no transaction held across HTTP calls - Hybrid searchApplications: FTS + per-user exact cosine search fused with RRF, matchedBy label, FTS-only fallback with provider cooldown - matchApplicationsToProfile tool: ranks against the user's profile documents and checks must-have terms explicitly with evidence; no similarity scores - Fix ts_rank Float->Double ClassCastException in existing FTS search - pgvector image for docker-compose, load test and Testcontainers Closes #111 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
Qodana for JVM5 new problems were found
View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/[email protected]
with:
upload-result: trueContact Qodana teamContact us at [email protected]
|
…'s V37
main added V37__add_assistant_quota.sql, which collided with this branch's
V37 ("Found more than one migration with version 37" in SemanticSearchPostgresIT).
The MariaDB-to-PostgreSQL migrator pins the Flyway version and requires
identical table sets, so it now targets V38 and treats semantic_embeddings as
PostgreSQL-only derived data: not compared or copied, required to be empty,
rebuilt by the application's backfill after cutover.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
`docker compose pull` + `up -d --remove-orphans` could pull, recreate or remove the PostgreSQL container on the VPS (e.g. once the pgvector image lands). Deploy now pulls and recreates only `app`, with --no-deps, and no longer removes orphans. PostgreSQL is upgraded manually. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
The merge of main (8927a8c) reverted TARGET_FLYWAY_VERSION to "37" while the schema now ends at V38, so the documented cutover would be refused. Adds a test that pins the constant to the highest PostgreSQL migration on disk. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
…reSQL 18 Production runs postgres:18. Testcontainers, the load test and docker-compose now use pgvector/pgvector:0.8.7-pg18 (pinned) instead of pg17. PostgreSQL 18 images moved PGDATA to /var/lib/postgresql/18/docker and the VOLUME to /var/lib/postgresql, and refuse to start on an older data directory, so dev compose mounts a new postgres18_data volume at the new path. README explains the dev upgrade; docs cover the production image switch (match the Debian base, back up, no apt-get in a running container). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #111
The blocker, #107 (the PostgreSQL migration), is already on
main.What it does
CREATE EXTENSION vectorand a newsemantic_embeddingstable. The vector column isvector(1024). Each row has a real foreign key withON DELETE CASCADEto its application or profile document and to its user. It also stores the embedded text, its SHA-256, the model, the dimensions, a status (PENDING/READY/FAILED/EMPTY/SOURCE_ERROR), the number of attempts and timestamps. All access goes through JDBC, so Hibernate never sees thevectortype andddl-auto: validateand the H2 test schema stay unchanged.RestClientcall toPOST /embeddingswith batching and timeouts. It sendsdimensions: 1024. If the provider ignores that field, the client keeps the first 1024 values and re-normalises. That is only valid for Matryoshka-trained models such as Qwen3-Embedding, and it can be turned off in config.EmbeddingSyncService, every minute): one polling loop handles backfill, change detection, model switches and retries:FOR UPDATE SKIP LOCKED, so several instances never embed the same row twice.searchApplications: full-text search and per-user cosine search each fetch up to 50 candidates with the same user and filters. The two lists are combined with Reciprocal Rank Fusion. Each result has amatchedByfield (KEYWORD,SEMANTICorKEYWORD_AND_SEMANTIC).Go,C#) and filter-only queries stay on the existing path. Aggregates still come from plain SQL.matchApplicationsToProfile: ranks applications against the user's own Drive profile documents. It checksrequiredTerms(stack, seniority, location, work modality, salary wording) literally against the vacancy text, ignoring case and accents and respecting word boundaries, soJavadoes not matchJavaScript. It returns evidence snippets and ranks only, never distances or percentages. The system prompt now tells the model not to turn similarity into a fit score and not to invent qualifications.semantic.embeddings.{latency, tokens, cost.usd, inputs, failures}coverage,backlog,exhaustedandsource_errorsassistant.search.latency{mode}Decisions worth reviewing
MATERIALIZEDCTE scans one user's rows exactly, using the(user_id, source_type, status)index. At 1024 dimensions an HNSW index can still be added later;docs/semantic-search.mdexplains when it would be worth it.ApplicationServiceor Drive, and backfill and retries reuse the same code. The cost is up to about one minute of delay before new content becomes searchable by meaning, while keyword search covers it immediately.SEMANTIC_SEARCH_DISABLED.PostgreSQL 18 everywhere
Production runs
postgres:18. Testcontainers, the load-test workflow anddocker-compose.ymlnow usepgvector/pgvector:0.8.7-pg18(pinned), so CI tests the same major version as production.PGDATAto/var/lib/postgresql/18/dockerand theVOLUMEto/var/lib/postgresql. They also refuse to start on an older data directory (this is in the officialdocker-library/postgres18 entrypoint). So compose now mounts a new volume,postgres18_data, at the new path.postgres_datavolume is left untouched. The README explains how to dump and restore if you want to keep local data.Deploy (
.github/workflows/backend.yml)The VPS step ran
docker compose pull && docker compose up -d --remove-orphans, which can pull, recreate or remove the PostgreSQL container. It now runsdocker compose pull app && docker compose up -d --no-deps app, so onlyappis managed.--remove-orphansis gone. PostgreSQL is upgraded by hand.docker compose config --serviceson the VPS returnsapp.MariaDB → PostgreSQL migrator
scripts/migrate_mariadb_to_postgresql.pypins the Flyway version and requires identical table sets on both sides. It now targets V38 and treatssemantic_embeddingsas PostgreSQL-only derived data: it is not compared or copied, it must be empty in the target, and the app's backfill rebuilds it after the cutover. Mergingmainreverted the pinned version to"37", which is now fixed. A new test ties the pinned version to the highest PostgreSQL migration on disk, so it can't drift again. The README cutover steps now say V1-V38.CREATE EXTENSIONfails if the binaries aren't on the server, so the app wouldn't start.image: postgres:18topgvector/pgvector:0.8.7-pg18-<debian>. Use the same Debian release as the current image, which you can check withcat /etc/os-releasein the container. That keeps glibc collations, and therefore text indexes, unchanged.postgres:18, so the existing volume is reused as is.apt-get installpgvector inside the running container: it disappears when the container is recreated.qwen/qwen3-embedding-8bis available, what it costs, and whether it supportsdimensions. I couldn't reach OpenRouter from the build environment.APP_SEMANTIC_SEARCH_MAX_COSINE_DISTANCE=0.65is an initial value that hasn't been calibrated on real data.Bugs found while testing
ts_rank(PostgreSQLreal, which the driver returns asjava.lang.Float) toDouble. As a result, every ranked Ask ApplyWell keyword search threw aClassCastExceptionon PostgreSQL. The existing ITs missed it because they build the schema withddl-auto, so the full-text search column never exists in them.mainsince this PR opened: on a fresh PostgreSQL database,maindid not boot because the assistant quota tables from feat(assistant): add per-user daily quota and anti-flood limits #110 had no PostgreSQL migration.fb0d05fadded them asV37__add_assistant_quota.sql. That collided with this PR's V37, which broke CI, so I mergedmainin and renumbered this PR's migration to V38.Tests
MockRestServiceServer) and provider cooldown.SemanticSearchPostgresIT: runs the real Flyway chain on pgvector (Testcontainers in CI, now on PostgreSQL 18). It covers tenant isolation, model and space filtering, the distance cutoff, structured filters, keyword vs semantic results, missing embeddings, profile matching, the sync lifecycle (backfill, idempotency, re-embedding on content or model change), retries and leases, exhausted rows and cascade deletes.main, against PostgreSQL 16 + pgvector 0.6 (no Docker or PG18 here): 312 tests in 56 classes pass, covering all unit tests,SemanticSearchPostgresITandJobTrackerApplicationTests. Flyway applies V37 (quota) and then V38 (embeddings). Migrator tests: 9/9. CI runs the suite on PG18./actuator/prometheus. That boot ran beforemain's quota fix, so it usedddl-auto=none.Docs:
docs/semantic-search.md🤖 Generated with Claude Code
https://claude.ai/code/session_01GfjfbRwirbsTBATemyhmxy